/*
 * Filename    : Graphic_Attach.java
 * Projectname : RamaShinta
 * Date        : Nov 18, 2012 , 7:38:34 PM 
 * 
 * Class for attaching our Image to Scene, Hud, etc
 * 
 * Subclass From Graphic_Load
 */

package com.amikomgamedev.ramashinta.graphic;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.camera.hud.HUD;
import org.andengine.entity.modifier.MoveXModifier;
import org.andengine.entity.modifier.MoveYModifier;
import org.andengine.entity.modifier.RotationModifier;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.TiledSprite;
import org.andengine.entity.sprite.ButtonSprite.OnClickListener;
import org.andengine.entity.sprite.Sprite;
import org.andengine.input.touch.TouchEvent;
import org.andengine.util.color.Color;

import com.amikomgamedev.ramashinta.ServerData;
import com.amikomgamedev.ramashinta.Utils;
import com.amikomgamedev.ramashinta.entity.Entity_Rama;
import com.amikomgamedev.ramashinta.game.Game_Config;

import android.content.Context;
import android.view.animation.RotateAnimation;

public class Graphic_Attach extends Graphic_Load
{

	public Graphic_Attach(Context contect, Scene p_Scene, HUD p_Hud, Camera p_Camera, OnClickListener p_Click)
	{
		super(contect, p_Scene, p_Hud, p_Camera, p_Click);

	}

	public void attachLogo()
	{
		if (spr_Logo == null)
		{
			spr_Logo = new Sprite(0, 0, Utils.getRatioW(LOGO_WIDTH), Utils.getRatioH(LOGO_HEIGHT), reg_Logo,
					getVertexBufferManager());
		}

		spr_Logo.setPosition(RES_WIDTH / 2 - (spr_Logo.getWidth() / 2), RES_HEIGHT / 2 - (spr_Logo.getHeight() / 2));
		m_Scene.attachChild(spr_Logo);

	}

	public void attachCreditBg()
	{
		if (spr_Credit_Bg == null)
			spr_Credit_Bg = new Sprite(0, 0, RES_WIDTH, RES_HEIGHT, reg_Credit_Bg, getVertexBufferManager());
		m_Scene.attachChild(spr_Credit_Bg);
	}

	public void attachHelpBg()
	{
		if (spr_Help_Bg == null)
			spr_Help_Bg = new Sprite(0, 0, RES_WIDTH, RES_HEIGHT, reg_Help_Bg, getVertexBufferManager());
		m_Scene.attachChild(spr_Help_Bg);
	}
	
	
	public void attachMenuSelectStage()
	{
		int X = 0;
		for(int i=0; i<MENU_SELECT_STAGE_BG.length;i++)
		{
			spr_Menu_Select_Stage[i] = new Sprite(
					X, 0,
					RES_WIDTH, 
					RES_HEIGHT, 
					reg_Menu_Select_Stage[i], 
					getVertexBufferManager());
			X += spr_Menu_Select_Stage[i].getWidth();
			m_Scene.attachChild(spr_Menu_Select_Stage[i]);
		}}
	
	public void attachMenuStageLingkaran()
	{
		int X	= (int) (RES_WIDTH/2 -  (MENU_SELECT_LINGKARAN_WIDTH*spr_Menu_Select_Stage.length)/2);
		for (int i = 0; i < spr_Menu_Select_Stage.length; i++)
		{
		    spr_Menu_Lingkaran = new TiledSprite(0, 0
				, Utils.getRatio(MENU_SELECT_LINGKARAN_WIDTH)
				, Utils.getRatio(MENU_SELECT_LINGKARAN_HEIGHT)
				, reg_Menu_Lingkaran
				, getVertexBufferManager());
		    
		    spr_Menu_Lingkaran.setPosition(
			    X,
			    RES_HEIGHT - spr_Menu_Lingkaran.getHeight());
		    m_Scene.attachChild(spr_Menu_Lingkaran);
		    lst_Menu_Stage_Lingkaran.add(spr_Menu_Lingkaran);
		    X +=  spr_Menu_Lingkaran.getWidth();
		}
	}
	
	
	public void attachArrowStage()
	{
		for (int i = 0; i < spr_Stage_Arrow.length; i++)
		{
			
		    spr_Stage_Arrow[i] = new TiledSprite(0, 0
				, Utils.getRatio(STAGE_ARROWWIDTH)
				, Utils.getRatio(STAGE_ARROWHEIGHT)
				, reg_Stage_Arrow
				, getVertexBufferManager());
		    
		    int X = 0;
			if(i == 1){
				X = (int) (RES_WIDTH - spr_Stage_Arrow[i].getWidth()) ;
				spr_Stage_Arrow[i].setCurrentTileIndex(1);
			}
		    
		    spr_Stage_Arrow[i].setPosition(X, (RES_HEIGHT/2)-STAGE_ARROW_TEX_HEIGHT/2);
		    m_Hud.registerTouchArea(spr_Stage_Arrow[i]);
		    m_Hud.attachChild(spr_Stage_Arrow[i]);
		}
	}
	

	public void attachStage()
	{
		spr_Stage_Bg = new Sprite(0, 0,
				RES_WIDTH, RES_HEIGHT, reg_Stage_Bg, getVertexBufferManager());
		m_Scene.attachChild(spr_Stage_Bg);
		
		for(int i=0; i < 5; i++)
		{
			spr_Icon_Stage[i] = new Sprite(0, 0,
					Utils.getRatio(300), Utils.getRatio(300),
					reg_Icon_Stage[i], getVertexBufferManager());
			m_Scene.attachChild(spr_Icon_Stage[i]);
		}
		
		for(int i=0; i < 2; i++)
		{
			for(int j=0; j < 5; j++)
			{
				if(i==0)
				{
					spr_Pointer[i][j] = new Sprite(POS_POINTER_X[j], POS_POITER_Y,
						Utils.getRatioH(32), Utils.getRatio(32), 
						reg_Pointer[i][j], getVertexBufferManager());
					
				}
				else
				{
					spr_Pointer[i][j] = new Sprite(POS_POINTER_X[j], POS_POITER_Y,
							Utils.getRatioH(32), Utils.getRatio(32), 
							reg_Pointer[i][j], getVertexBufferManager());
					spr_Pointer[i][j].setVisible(false);
				}
				m_Scene.attachChild(spr_Pointer[i][j]);
			}
		}
	}
	
	
	public void attachLoadingBg()
	{
		if (spr_Loading_Bg == null)
			spr_Loading_Bg = new Sprite(0, 0, RES_WIDTH, RES_HEIGHT, reg_Loading_Bg, getVertexBufferManager());
		m_Scene.attachChild(spr_Loading_Bg);
	}

	public void attachMenuUtama()
	{
		attachMenuBg();
		createButtonMenuPressed();
		attachButtonMenu();
		attachCoklatCupcorn();
		attachFacebook();
		attachTwitter();
		attachGear();
	}

	public void attachGamePLayEntity()
	{
		attachGameplayBg();
		attachMcShinta();
		attachMcRama();
		attachMcRahwana();
		
	}
	
	public void attachGamePlay(){
		attachIndikatorBar();
		CreateSprButtonPanah();
		AttachButtonPanahPressed();
		AttachButtonPanah();
		attachButtonMove();
		attachBtnPause();
		attachBarrier();
		attachBarrierRahwana();
		attachKandang();
		attachStatApiRama();
		attachStatApiRahwana();
		attachStatBonekaRahwana();
		attachStatBonekaRama();
		attachStatChocoRahwana();
		attachStatChocoRama();
		attachStatPoisonLiquid();
		attachStatBeeHive();
		attachCelebrasiRama();
		attachCelebrasiRahwana();
	}

	public void attachMenuLevel()
	{
		attachMenuLevelBg();
		attachMenuLevelLove();
	}

	public void attachPanah()
	{
		CreateSprButtonPanah();
		AttachButtonPanah();
	}
	
	public void attachStateWin()
	{
		attachLoveAndPanah();
		attachBtnTryNextWin();
		attachBtnTryWin();
		attachBtnNextWin();
	}
	
	public void attachStateLastWin()
	{
		attachLoveAndPanah();
		attachBtnTryWinStandAlone();
	}
	
	public void attachStateLose()
	{
		attachBreakHeart();
		attachBtnTryWinStandAlone();
	}
	
	private void attachStatApiRama()
	{
			spr_Stat_ApiRama = new Sprite(0, 0, Utils.getRatioW(ITEM_API_WIDTH),
					Utils.getRatioH(ITEM_API_HEIGHT), reg_Item_Api, getVertexBufferManager());

		spr_Gameplay_bg.attachChild(spr_Stat_ApiRama);
		spr_Stat_ApiRama.setPosition(Utils.getRatioW(90), spr_Menu_Pause_Btn.getHeight());
		spr_Stat_ApiRama.setScale(0.75f);
		spr_Stat_ApiRama.setVisible(false);
	}
	
	private void attachStatApiRahwana()
	{
			spr_Stat_ApiRahwana = new Sprite(0, 0, Utils.getRatioW(ITEM_API_WIDTH),
					Utils.getRatioH(ITEM_API_HEIGHT), reg_Item_Api, getVertexBufferManager());

		spr_Gameplay_bg.attachChild(spr_Stat_ApiRahwana);
		spr_Stat_ApiRahwana.setPosition(RES_WIDTH-Utils.getRatioW(90)-spr_Stat_ApiRahwana.getWidth(), spr_Menu_Pause_Btn.getHeight());
		spr_Stat_ApiRahwana.setScale(0.75f);
		spr_Stat_ApiRahwana.setVisible(false);
	}
	
	private void attachStatBonekaRahwana()
	{
		spr_Stat_BonekaRahwana = new Sprite(0, 0, Utils.getRatioW(ITEM_BONEKA_WIDTH),
					Utils.getRatioH(ITEM_BONEKA_HEIGHT), reg_Item_Boneka, getVertexBufferManager());

		spr_Gameplay_bg.attachChild(spr_Stat_BonekaRahwana);
		spr_Stat_BonekaRahwana.setPosition(spr_Stat_ApiRahwana.getX()-spr_Stat_BonekaRahwana.getWidth(), 
				spr_Menu_Pause_Btn.getHeight());
		spr_Stat_BonekaRahwana.setScale(0.75f);
		spr_Stat_BonekaRahwana.setVisible(false);
	}
	
	private void attachStatBonekaRama()
	{
		spr_Stat_BonekaRama = new Sprite(0, 0, Utils.getRatioW(ITEM_BONEKA_WIDTH),
					Utils.getRatioH(ITEM_BONEKA_HEIGHT), reg_Item_Boneka, getVertexBufferManager());

		spr_Gameplay_bg.attachChild(spr_Stat_BonekaRama);
		spr_Stat_BonekaRama.setPosition(spr_Stat_ApiRama.getX()+spr_Stat_BonekaRama.getWidth(), 
				spr_Menu_Pause_Btn.getHeight());
		spr_Stat_BonekaRama.setScale(0.75f);
		spr_Stat_BonekaRama.setVisible(false);
	}
	
	private void attachStatPoisonLiquid()
	{
		int X = 0;
		for(int i=0; i<spr_Stat_PoisonLQ.length; i++){
			spr_Stat_PoisonLQ[i]= new Sprite(0, 0, Utils.getRatioW(ITEM_POISONLQD_WIDTH),
					Utils.getRatioH(ITEM_POISONLQD_HEIGHT), reg_Item_PoisonLQ, getVertexBufferManager());
			
			if(i == 0){
				X = (int) (spr_Stat_BonekaRama.getX() + spr_Stat_PoisonLQ[i].getWidth());
			}else{
				X = (int) (spr_Stat_BonekaRahwana.getX() - spr_Stat_PoisonLQ[i].getWidth());
			}
			spr_Stat_PoisonLQ[i].setPosition(X, spr_Menu_Pause_Btn.getHeight());
			spr_Gameplay_bg.attachChild(spr_Stat_PoisonLQ[i]);
			spr_Stat_PoisonLQ[i].setScale(0.75f);
			spr_Stat_PoisonLQ[i].setVisible(false);
			
		}
	}
	
	private void attachStatBeeHive()
	{
		int X = 0;
		for(int i=0; i<spr_Stat_BeeHive.length; i++){
			spr_Stat_BeeHive[i]= new Sprite(0, 0, Utils.getRatioW(ITEM_BEEHIVE_WIDTH),
					Utils.getRatioH(ITEM_BEEHIVE_HEIGHT), reg_Item_BeeHive, getVertexBufferManager());
			
			if(i == 0){
				X = (int) (spr_Stat_PoisonLQ[0].getX() + spr_Stat_BeeHive[i].getWidth());
			}else{
				X = (int) (spr_Stat_PoisonLQ[1].getX() - spr_Stat_BeeHive[i].getWidth());
			}
			spr_Stat_BeeHive[i].setPosition(X, spr_Menu_Pause_Btn.getHeight());
			spr_Gameplay_bg.attachChild(spr_Stat_BeeHive[i]);
			spr_Stat_BeeHive[i].setScale(0.75f);
			spr_Stat_BeeHive[i].setVisible(false);
			
		}

		
		
	}
	
	private void attachStatChocoRahwana()
	{
			spr_Stat_ChocoRahwana = new Sprite(0, 0, Utils.getRatioW(ITEM_CHOCO_WIDTH),
					Utils.getRatioH(ITEM_CHOCO_HEIGHT), reg_Item_Choco, getVertexBufferManager());

		spr_Gameplay_bg.attachChild(spr_Stat_ChocoRahwana);
		spr_Stat_ChocoRahwana.setPosition(spr_Stat_BonekaRahwana.getX()-spr_Stat_ChocoRahwana.getWidth(), 
				spr_Menu_Pause_Btn.getHeight());
		spr_Stat_ChocoRahwana.setScale(0.75f);
		spr_Stat_ChocoRahwana.setVisible(false);
	}
	
	private void attachStatChocoRama()
	{
			spr_Stat_ChocoRama = new Sprite(0, 0, Utils.getRatioW(ITEM_CHOCO_WIDTH),
					Utils.getRatioH(ITEM_CHOCO_HEIGHT), reg_Item_Choco, getVertexBufferManager());

		spr_Gameplay_bg.attachChild(spr_Stat_ChocoRama);
		spr_Stat_ChocoRama.setPosition(spr_Stat_BonekaRama.getX()+spr_Stat_ChocoRama.getWidth(), 
				spr_Menu_Pause_Btn.getHeight());
		spr_Stat_ChocoRama.setScale(0.75f);
		spr_Stat_ChocoRama.setVisible(false);
	}
	
	private void attachBarrier()
	{
		if (spr_BarrierRama == null)
			spr_BarrierRama = new Sprite(0, 0, Utils.getRatioW(BARRIER_WIDTH),
					Utils.getRatioH(BARRIER_HEIGHT), reg_Barrier, getVertexBufferManager());

		spr_Mc_Rama.attachChild(spr_BarrierRama);
		spr_BarrierRama.setVisible(false);
	}
	
	private void attachBarrierRahwana()
	{
		if (spr_BarrierRahwana == null)
			spr_BarrierRahwana = new Sprite(0, 0, Utils.getRatioW(BARRIER_WIDTH),
					Utils.getRatioH(BARRIER_HEIGHT), reg_Barrier, getVertexBufferManager());

		spr_Mc_Rahwana.attachChild(spr_BarrierRahwana);
		spr_BarrierRahwana.setVisible(false);
	}
	
	private void attachBreakHeart()
	{
		if (spr_Love_Lose == null)
		{
			spr_Love_Lose = new Sprite(0, 0, Utils.getRatioW(LOVE_LOSE_WIDTH), Utils.getRatioH(LOVE_LOSE_HEIGHT),
					reg_Love_Lose, getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Love_Lose);

		spr_Love_Lose.setPosition(RES_WIDTH / 2 - spr_Love_Lose.getWidth() / 2, RES_HEIGHT / 2 - spr_Love_Lose.getHeight()
				/ 2);
	}
	

	private void attachBtnTryNextWin()
	{
		if (spr_Btn_TryNext_Win == null)
		{
			spr_Btn_TryNext_Win = new Sprite(
					0, 0,
					Utils.getRatioW(BTN_TRY_WIN_WIDTH), Utils.getRatioH(BTN_TRY_WIN_HEIGHT),
					reg_Btn_TryNext_Win, getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Btn_TryNext_Win);
		spr_Btn_TryNext_Win.setPosition(RES_WIDTH / 2 - spr_Btn_TryNext_Win.getWidth() / 2, Utils.getRatio(400));

	}
	
	private void attachBtnNextWin()
	{
		if (spr_Btn_Next_Win == null)
		{
			spr_Btn_Next_Win = new Sprite(
					0, 0,
					Utils.getRatioW(BTN_NEXT_WIDTH), Utils.getRatioH(BTN_NEXT_HEIGHT),
					reg_Btn_Next_Win, getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Btn_Next_Win);
		spr_Btn_Next_Win.setPosition((RES_WIDTH / 2 - spr_Btn_TryNext_Win.getWidth() / 2)+spr_Btn_Next_Win.getWidth(), Utils.getRatio(400));
		m_Scene.registerTouchArea(spr_Btn_Next_Win);
	}
	
	private void attachBtnTryWin()
	{
		if (spr_Btn_Try_Win == null)
		{
			spr_Btn_Try_Win = new Sprite(
					0, 0,
					Utils.getRatioW(BTN_TRY_WIDTH), Utils.getRatioH(BTN_TRY_HEIGHT),
					reg_Btn_Try_Win, getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Btn_Try_Win);
		spr_Btn_Try_Win.setPosition(RES_WIDTH / 2 - spr_Btn_TryNext_Win.getWidth() / 2, Utils.getRatio(400));
		m_Scene.registerTouchArea(spr_Btn_Try_Win);

	}
	
	private void attachBtnTryWinStandAlone()
	{
		if (spr_Btn_Try_Win == null)
		{
			spr_Btn_Try_Win = new Sprite(
					0, 0,
					Utils.getRatioW(BTN_TRY_WIDTH), Utils.getRatioH(BTN_TRY_HEIGHT),
					reg_Btn_Try_Win, getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Btn_Try_Win);
		spr_Btn_Try_Win.setPosition(RES_WIDTH / 2 - spr_Btn_Try_Win.getWidth() / 2, Utils.getRatio(400));
		m_Scene.registerTouchArea(spr_Btn_Try_Win);

	}

	private void attachLoveAndPanah()
	{
		if (spr_Love_Win == null)
		{
			spr_Love_Win = new Sprite(0, 0, Utils.getRatioW(LOVE_WIN_WIDTH), Utils.getRatioH(LOVE_WIN_HEIGHT),
					reg_Love_Win, getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Love_Win);

		spr_Love_Win.setPosition(RES_WIDTH / 2 - spr_Love_Win.getWidth() / 2, RES_HEIGHT / 2 - spr_Love_Win.getHeight()
				/ 2);

		if (spr_Arrow_Win == null)
		{
			spr_Arrow_Win = new Sprite(
					0, 0,
					Utils.getRatioW(ARROW_WIN_WIDTH), Utils.getRatioH(ARROW_WIN_HEIGHT),
					reg_Arrow_Win,
					getVertexBufferManager());
		}
		spr_Love_Win.attachChild(spr_Arrow_Win);
		spr_Arrow_Win.setPosition(
				spr_Love_Win.getWidth() / 2 - spr_Arrow_Win.getWidth() / 2,
				spr_Love_Win.getHeight() / 2 - spr_Arrow_Win.getHeight() / 2);

	}

	
	private void createPanahGameplay()
	{
		if (spr_Panah_Gameplay == null)
		{
			spr_Panah_Gameplay = new Sprite(0, 0, Utils.getRatioW(PANAH_GAMEPLAY_WIDTH),
					Utils.getRatioH(PANAH_GAMEPLAY_HEIGHT), reg_Panah_Gameplay, getVertexBufferManager());
		}
	}


	public void attachMenuPause(Scene p_Scene)
	{
		if (spr_Menu_Pause_Bg == null)
		{
			spr_Menu_Pause_Bg = new Sprite(0, 0, Utils.getRatioW(MENU_PAUSE_BG_WIDTH),
					Utils.getRatioH(MENU_PAUSE_BG_HEIGHT), reg_Menu_Pause_Bg, getVertexBufferManager());
		}
		spr_Menu_Pause_Bg.setPosition(RES_WIDTH / 2 - spr_Menu_Pause_Bg.getWidth() / 2, RES_HEIGHT / 2
				- spr_Menu_Pause_Bg.getHeight() / 2);
		p_Scene.attachChild(spr_Menu_Pause_Bg);
	}

	public void attachPauseRestart(Scene p_Scene)
	{
		if (spr_Pause_Btn_Restart == null)
		{
			spr_Pause_Btn_Restart = new Sprite(0, 0, Utils.getRatioW(PAUSE_BTN_WIDTH),
					Utils.getRatioH(PAUSE_BTN_HEIGHT), reg_Pause_Btn_Restart, getVertexBufferManager());
		}
		spr_Pause_Btn_Restart.setPosition(spr_Menu_Pause_Bg.getX()+spr_Menu_Pause_Bg.getWidth()-spr_Pause_Btn_Restart.getWidth()-Utils.getRatioW(2), 
				spr_Menu_Pause_Bg.getY()+spr_Pause_Btn_Continue.getHeight()+ Utils.getRatioH(8));
		p_Scene.attachChild(spr_Pause_Btn_Restart);
		m_Scene.registerTouchArea(spr_Pause_Btn_Restart);
	}
	
	public void attachPauseContinue(Scene p_Scene)
	{
		if (spr_Pause_Btn_Continue == null)
		{
			spr_Pause_Btn_Continue = new Sprite(0, 0, Utils.getRatioW(PAUSE_BTN_WIDTH),
					Utils.getRatioH(PAUSE_BTN_HEIGHT), reg_Pause_Btn_Continue, getVertexBufferManager());
		}
		spr_Pause_Btn_Continue.setPosition(spr_Menu_Pause_Bg.getX()+spr_Menu_Pause_Bg.getWidth()-spr_Pause_Btn_Continue.getWidth()-Utils.getRatioW(2), 
				spr_Menu_Pause_Bg.getY()+ Utils.getRatioH(8));
		p_Scene.attachChild(spr_Pause_Btn_Continue);
		m_Scene.registerTouchArea(spr_Pause_Btn_Continue);
	}
	
	public void attachPauseMainMenu(Scene p_Scene)
	{
		if (spr_Pause_Btn_MainMenu == null)
		{
			spr_Pause_Btn_MainMenu = new Sprite(0, 0, Utils.getRatioW(PAUSE_BTN_WIDTH),
					Utils.getRatioH(PAUSE_BTN_HEIGHT), reg_Pause_Btn_MainMenu, getVertexBufferManager());
		}
		spr_Pause_Btn_MainMenu.setPosition(spr_Menu_Pause_Bg.getX()+spr_Menu_Pause_Bg.getWidth()-spr_Pause_Btn_Restart.getWidth()-Utils.getRatioW(2), 
				spr_Menu_Pause_Bg.getY()+spr_Pause_Btn_Continue.getHeight()+spr_Pause_Btn_Restart.getHeight()+ Utils.getRatioH(8));
		p_Scene.attachChild(spr_Pause_Btn_MainMenu);
		m_Scene.registerTouchArea(spr_Pause_Btn_MainMenu);
	}

	private void attachBtnPause()
	{
		if (spr_Menu_Pause_Btn == null)
		{
			spr_Menu_Pause_Btn = new Sprite(0, 0, Utils.getRatioW(MENU_PAUSE_BTN_WIDTH),
					Utils.getRatioH(MENU_PAUSE_BTN_HEIGHT), reg_Menu_Pause_Btn, getVertexBufferManager());
		}

		spr_Menu_Pause_Btn.setPosition(Utils.getRatioW(710)-spr_Menu_Pause_Btn.getWidth(), Utils.getRatio(0));
		m_Scene.registerTouchArea(spr_Menu_Pause_Btn);
		m_Scene.attachChild(spr_Menu_Pause_Btn);

	}

	private void attachMenuLevelLove()
	{
		int Row2 = 2;
		for (int i = 0; i < spr_Menu_Level_Love.length; i++)
		{
				spr_Menu_Level_Love[i] = new Sprite(0, 0, Utils.getRatio(MENU_LEVEL_LOVE_WIDTH),
						Utils.getRatio(MENU_LEVEL_LOVE_HEIGHT), reg_Menu_Level_Love, getVertexBufferManager());
				spr_Menu_Level_Bg.attachChild(spr_Menu_Level_Love[i]);
			if(i>=0&&i<5){
				spr_Menu_Level_Love[i].setY(0 + spr_Menu_Level_Love[i].getHeight());
			}
			if(i>=5&&i<10){
				spr_Menu_Level_Love[i].setY(RES_HEIGHT / Row2 - spr_Menu_Level_Love[i].getHeight()/9);
			}
//			if(i>4&&i<7){
//				spr_Menu_Level_Love[i].setY(RES_HEIGHT / Row3 - spr_Menu_Level_Love[i].getHeight() / Row3);
//			}
//			if(i==1){
//				spr_Menu_Level_Love[i].setX(Utils.getRatio(150) * (2));
//			}
			spr_Menu_Level_Love[i].setX(Utils.getRatioW(120) * ((i%5)+1));
			Utils.TRACE("pos X "+spr_Menu_Level_Love[i].getX());
			Utils.TRACE("pos Y "+spr_Menu_Level_Love[i].getY());
			

			m_Scene.registerTouchArea(spr_Menu_Level_Love[i]);

		}

	}

	private void attachMenuLevelBtnBack()
	{
		if (spr_Menu_Level_Btn_Back == null)
			spr_Menu_Level_Btn_Back = new Sprite(0, 0, Utils.getRatio(MENU_LEVEL_BTN_BACK_WIDTH),
					Utils.getRatio(MENU_LEVEL_BTN_BACK_HEIGHT), reg_Menu_Level_Btn_Back, getVertexBufferManager());
		spr_Menu_Level_Bg.attachChild(spr_Menu_Level_Btn_Back);
	}

	private void attachMenuLevelBg()
	{
		if (spr_Menu_Level_Bg == null)
			spr_Menu_Level_Bg = new Sprite(0, 0, RES_WIDTH, RES_HEIGHT, reg_Menu_Level_Bg, getVertexBufferManager());
		m_Scene.attachChild(spr_Menu_Level_Bg);
	}

	private void attachMenuBg()
	{
		if (spr_Menu_Bg == null)
			spr_Menu_Bg = new Sprite(0, 0, RES_WIDTH, RES_HEIGHT, reg_Menu_Bg, getVertexBufferManager());
		m_Scene.attachChild(spr_Menu_Bg);
		m_Scene.registerTouchArea(spr_Menu_Bg);
	}

	private void attachButtonMenu()
	{
		for (int i = 0; i < BUTTON_MENU.length; i++)
		{
			if (spr_Button_Menu[i] == null)
				spr_Button_Menu[i] = new Sprite(0, 0, Utils.getRatioW(MENU_BUTTON_WIDTH),
						Utils.getRatioH(MENU_BUTTON_HEIGHT), reg_Button_Menu[i], getVertexBufferManager());
			spr_Menu_Bg.attachChild(spr_Button_Menu[i]);
			m_Scene.registerTouchArea(spr_Button_Menu[i]);
		}

		// btn play
		spr_Button_Menu[0].setPosition(Utils.getRatioW(240), Utils.getRatioH(240));
		// btn help
		spr_Button_Menu[1].setPosition(Utils.getRatioW(240), Utils.getRatioH(300));
		// btn credit
		spr_Button_Menu[2].setPosition(Utils.getRatioW(340), Utils.getRatioH(300));
		// btn multi
		spr_Button_Menu[3].setPosition(Utils.getRatioW(340), Utils.getRatioH(240));
		
		spr_Button_Menu[0].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu[0].getX(), Utils.getRatioW(440)));
		spr_Button_Menu[1].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu[1].getX(), Utils.getRatioW(440)));
		spr_Button_Menu[2].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu[2].getX(), Utils.getRatioW(540)));
		spr_Button_Menu[3].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu[3].getX(), Utils.getRatioW(540)));
		
		spr_Button_Menu[0].setVisible(true);
		// btn help
		spr_Button_Menu[1].setVisible(true);
		// btn credit
		spr_Button_Menu[2].setVisible(true);
		// btn multi
		spr_Button_Menu[3].setVisible(true);

	}
	
	private void createButtonMenuPressed()
	{
		for (int i = 0; i < BUTTON_MENU_PRESSED.length; i++)
		{
				spr_Button_Menu_Pressed[i] = new Sprite(0, 0, Utils.getRatioW(MENU_BUTTON_WIDTH),
						Utils.getRatioH(MENU_BUTTON_HEIGHT), reg_Button_Menu_Pressed[i], getVertexBufferManager());
				spr_Menu_Bg.attachChild(spr_Button_Menu_Pressed[i]);
			m_Scene.registerTouchArea(spr_Button_Menu_Pressed[i]);
		}

		// btn play
		spr_Button_Menu_Pressed[0].setPosition(Utils.getRatioW(440), Utils.getRatioH(240));
		// btn help
		spr_Button_Menu_Pressed[1].setPosition(Utils.getRatioW(440), Utils.getRatioH(300));
		// btn credit
		spr_Button_Menu_Pressed[2].setPosition(Utils.getRatioW(540), Utils.getRatioH(300));
		// btn multi
		spr_Button_Menu_Pressed[3].setPosition(Utils.getRatioW(540), Utils.getRatioH(240));
		
//		spr_Button_Menu_Pressed[0].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu_Pressed[0].getX(), Utils.getRatioW(440)));
//		spr_Button_Menu_Pressed[1].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu_Pressed[1].getX(), Utils.getRatioW(440)));
//		spr_Button_Menu_Pressed[2].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu_Pressed[2].getX(), Utils.getRatioW(540)));
//		spr_Button_Menu_Pressed[3].registerEntityModifier(new MoveXModifier(2f, spr_Button_Menu_Pressed[3].getX(), Utils.getRatioW(540)));
		
		// btn play
				spr_Button_Menu_Pressed[0].setVisible(false);
				// btn help
				spr_Button_Menu_Pressed[1].setVisible(false);
				// btn credit
				spr_Button_Menu_Pressed[2].setVisible(false);
				// btn multi
				spr_Button_Menu_Pressed[3].setVisible(false);

	}
	
	private void attachCoklatCupcorn()
	 {
	 if (spr_Menu_Coklat == null)
	 spr_Menu_Coklat = new Sprite(0, 0,
	 Utils.getRatioW(MENU_COKLAT_WIDTH),
	 Utils.getRatioH(MENU_COKLAT_HEIGHT), reg_Menu_Coklat,
	 getVertexBufferManager());
	 spr_Menu_Bg.attachChild(spr_Menu_Coklat);
	 spr_Menu_Coklat.setPosition(Utils.getRatioW(135), Utils.getRatioH(230));
	 } 
	
	private void attachGear()
	{
		if (spr_Gear == null){
			spr_Gear = new Sprite(0, 0, Utils.getRatioW(GEAR_WIDTH), Utils.getRatioH(GEAR_HEIGHT), reg_Gear, getVertexBufferManager());
		}
		spr_Menu_Bg.attachChild(spr_Gear);
		spr_Gear.setPosition(RES_WIDTH-spr_Gear.getWidth(), RES_HEIGHT-spr_Gear.getHeight());
		spr_Gear.registerEntityModifier(new RotationModifier(2f, 0, 360));
		m_Scene.registerTouchArea(spr_Gear);
	}
	
	private void attachFacebook()
	{
		if (spr_Facebook == null){
			spr_Facebook = new Sprite(0, 0, Utils.getRatioW(GEAR_WIDTH), Utils.getRatioH(GEAR_HEIGHT), reg_Facebook, getVertexBufferManager());
		}
		spr_Menu_Bg.attachChild(spr_Facebook);
		spr_Facebook.setPosition(RES_WIDTH-spr_Facebook.getWidth(), RES_HEIGHT-spr_Facebook.getHeight());
		spr_Facebook.registerEntityModifier(new MoveYModifier(1.3f, spr_Facebook.getY(), spr_Facebook.getY()-spr_Facebook.getHeight()));
	}
	
	private void attachTwitter()
	{
		if (spr_Twitter == null){
			spr_Twitter = new Sprite(0, 0, Utils.getRatioW(GEAR_WIDTH), Utils.getRatioH(GEAR_HEIGHT), reg_Twitter, getVertexBufferManager());
		}
		spr_Menu_Bg.attachChild(spr_Twitter);
		spr_Twitter.setPosition(RES_WIDTH-spr_Facebook.getWidth(), RES_HEIGHT-spr_Facebook.getHeight());
		spr_Twitter.registerEntityModifier(new MoveYModifier(1.3f, spr_Twitter.getY(), spr_Twitter.getY()-(spr_Twitter.getHeight()*2)));
	}

	private void attachGameplayBg()
	{

		if (ServerData.getLevelSelection() == ServerData.LEVEL_KAYANGAN)
		{
			spr_Gameplay_bg = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_BG_WIDTH), Utils.getRatioH(GAMEPLAY_BG_HEIGHT),
					reg_Gameplay_bg[ServerData.LEVEL_KAYANGAN], getVertexBufferManager());
		} else
		{

			spr_Gameplay_bg = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_BG_WIDTH), Utils.getRatioH(GAMEPLAY_BG_HEIGHT),
					reg_Gameplay_bg[ServerData.LEVEL_HUTAN], getVertexBufferManager());
		}
		m_Scene.attachChild(spr_Gameplay_bg);

		for (int i = 0; i < rect_Gameplay.length; i++)
		{
			rect_Gameplay[i] = new Rectangle(0, 0, RES_WIDTH, 2f, getVertexBufferManager());
			if (Game_Config.DEBUG)
			{
				rect_Gameplay[i].setColor(Color.RED);
			} else
			{
				rect_Gameplay[i].setColor(Color.TRANSPARENT);
			}

			spr_Gameplay_bg.attachChild(rect_Gameplay[i]);
			Utils.TRACE("attach Rectangle " + i);
		}

		// atas
		rect_Gameplay[0].setPosition(0, Utils.getRatio(100));
		// bawah
		rect_Gameplay[1].setPosition(0, RES_HEIGHT - 2);
	}
	
	public void createGameplayPf()
	{
		for (int i = 0; i < GAMEPLAY_PLATFORM.length; i++)
		{
				spr_Gameplay_Pf[i] = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_PF_WIDTH),
						Utils.getRatioH(GAMEPLAY_PF_HEIGHT), reg_Gameplay_Pf[i], getVertexBufferManager());
		}
	}

	private void attachIndikatorBar()
	{
		if (spr_Indikator_Bar_kiri == null)
			spr_Indikator_Bar_kiri = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_INDIKATOR_BAR_WIDTH),
					Utils.getRatioH(GAMEPLAY_INDIKATOR_BAR_HEIGHT), reg_Indikator_Bar, getVertexBufferManager());
		if (spr_Indikator_Bar_kanan == null)
			spr_Indikator_Bar_kanan = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_INDIKATOR_BAR_WIDTH),
					Utils.getRatioH(GAMEPLAY_INDIKATOR_BAR_HEIGHT), reg_Indikator_Bar, getVertexBufferManager());

		spr_Indikator_Bar_kiri.setPosition(0, 0);
		spr_Indikator_Bar_kanan.setPosition(RES_WIDTH - (spr_Indikator_Bar_kanan.getWidth()), 0);

		spr_Gameplay_bg.attachChild(spr_Indikator_Bar_kiri);
		spr_Indikator_Bar_kiri.setVisible(false);
		spr_Gameplay_bg.attachChild(spr_Indikator_Bar_kanan);
		spr_Indikator_Bar_kanan.setVisible(false);
	}
	
	private void attachKandang(){
		if (spr_Kandang == null){
			spr_Kandang = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_KANDANG_WIDTH),
					Utils.getRatioH(GAMEPLAY_KANDANG_HEIGHT), reg_Kandang, getVertexBufferManager());
		}
		spr_Kandang.setPosition(rect_BalokShinta.getX()-Utils.getRatioW(15),  rect_BalokShinta.getY() - spr_Kandang.getHeight()+Utils.getRatioH(10));
		spr_Gameplay_bg.attachChild(spr_Kandang);
		Utils.TRACE("pos x "+spr_Kandang.getX());
		Utils.TRACE("pos y "+spr_Kandang.getY());
	}

	private void attachMcShinta()
	{
		if (rect_BalokShinta == null)
			rect_BalokShinta = new Rectangle(0, 0, Utils.getRatioW(100), Utils.getRatioH(10), getVertexBufferManager());
		rect_BalokShinta.setColor(Color.BLACK);
		rect_BalokShinta.setPosition(RES_WIDTH / 2 - (rect_BalokShinta.getWidth() / 2), Utils.getRatio(100));
		rect_BalokShinta.setVisible(false);

		if (spr_Mc_Shinta == null)
			spr_Mc_Shinta = new AnimatedSprite(0, 0, Utils.getRatioW(SPR_MC_SHINTA_WIDTH),
					Utils.getRatioH(SPR_MC_SHINTA_HEIGHT), reg_Mc_Shinta, getVertexBufferManager());
		spr_Mc_Shinta.setPosition(rect_BalokShinta.getX(), rect_BalokShinta.getY() - spr_Mc_Shinta.getHeight());

		spr_Gameplay_bg.attachChild(rect_BalokShinta);
		spr_Gameplay_bg.attachChild(spr_Mc_Shinta);

	}
	
//	private void attachAnimPanahApi(){
//		if (spr_AnimPanahApi == null)
//			spr_AnimPanahApi = new AnimatedSprite(0, 0, Utils.getRatioW(SPR_PANAH_API_WIDTH),
//					Utils.getRatioH(SPR_PANAH_API_HEIGHT), reg_Anim_Panah_Api, getVertexBufferManager());
//		spr_AnimPanahApi.setPosition(rect_BalokShinta.getX(), rect_BalokShinta.getY() - spr_Mc_Shinta.getHeight());
//
//		spr_Gameplay_bg.attachChild(spr_Mc_Shinta);
//	}

	private void CreateSprButtonPanah()
	{
		for (int i = 0; i < GAMEPLAY_BTN_PANAH.length; i++)
		{
				spr_Gameplay_Btn_Panah[i] = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_BTN_PANAH_WIDTH),
						Utils.getRatioH(GAMEPLAY_BTN_PANAH_HEIGHT), reg_Gameplay_Btn_Panah[i], getVertexBufferManager());
				m_Scene.registerTouchArea(spr_Gameplay_Btn_Panah[i]);

		}

	}

	private void AttachButtonPanah()
	{
		spr_Gameplay_bg.attachChild(spr_Gameplay_Btn_Panah[0]);
		spr_Gameplay_Btn_Panah[0].setPosition(RES_WIDTH - spr_Gameplay_Btn_Panah[0].getWidth()-Utils.getRatioW(10), RES_HEIGHT
				- spr_Gameplay_Btn_Panah[0].getHeight()-Utils.getRatioH(5));
	}

	private void AttachButtonPanahPressed()
	{
		spr_Gameplay_bg.attachChild(spr_Gameplay_Btn_Panah[1]);
		spr_Gameplay_Btn_Panah[1].setPosition(RES_WIDTH - spr_Gameplay_Btn_Panah[1].getWidth()-Utils.getRatioW(10), RES_HEIGHT
				- spr_Gameplay_Btn_Panah[1].getHeight()-Utils.getRatioH(5));
	}

	private void attachButtonMove()
	{
		for (int i = 0; i < GAMEPLAY_BUTTON_MOVE.length; i++)
		{
			if (spr_Gameplay_Button_Move[i] == null)
				spr_Gameplay_Button_Move[i] = new Sprite(0, 0, Utils.getRatioW(GAMEPLAY_BTN_MOVE_WIDTH),
						Utils.getRatioH(GAMEPLAY_BTN_MOVE_HEIGHT), reg_Gameplay_Button_Move[i],
						getVertexBufferManager());
			m_Scene.registerTouchArea(spr_Gameplay_Button_Move[i]);

		}
		spr_Gameplay_bg.attachChild(spr_Gameplay_Button_Move[0]);
		spr_Gameplay_bg.attachChild(spr_Gameplay_Button_Move[1]);
		spr_Gameplay_bg.attachChild(spr_Gameplay_Button_Move[2]);
		spr_Gameplay_bg.attachChild(spr_Gameplay_Button_Move[3]);

		// btn down pressed
		spr_Gameplay_Button_Move[3]
				.setPosition(Utils.getRatioW(10), RES_HEIGHT - spr_Gameplay_Button_Move[3].getHeight()-Utils.getRatioH(10));

		// btn up pressed
		spr_Gameplay_Button_Move[2]
				.setPosition(Utils.getRatioW(10), spr_Gameplay_Button_Move[3].getY()
						- spr_Gameplay_Button_Move[0].getHeight()-Utils.getRatioH(10));

		// btn down
		spr_Gameplay_Button_Move[1]
				.setPosition(Utils.getRatioW(10), RES_HEIGHT - spr_Gameplay_Button_Move[1].getHeight()-Utils.getRatioH(10));
		// btn up
		spr_Gameplay_Button_Move[0]
				.setPosition(Utils.getRatioW(10), spr_Gameplay_Button_Move[1].getY()
						- spr_Gameplay_Button_Move[0].getHeight()-Utils.getRatioH(10));
	}

	private void attachMcRama()
	{
		if (spr_Mc_Rama == null)
			spr_Mc_Rama = new AnimatedSprite(0, 0, Utils.getRatioW(SPR_MC_RAMA_WIDTH),
					Utils.getRatioH(SPR_MC_RAMA_HEIGHT), reg_Mc_Rama, getVertexBufferManager());

		spr_Mc_Rama.setPosition(Utils.getRatio(100), Utils.getRatio(100));
		spr_Gameplay_bg.attachChild(spr_Mc_Rama);
		spr_Mc_Rama.setVisible(true);
	}

	private void attachMcRahwana()
	{
		if (spr_Mc_Rahwana == null)
			spr_Mc_Rahwana = new AnimatedSprite(0, 0, Utils.getRatioW(SPR_MC_RAHWANA_WIDTH),
					Utils.getRatioH(SPR_MC_RAMA_HEIGHT), reg_Mc_Rahwana, getVertexBufferManager());
		spr_Mc_Rahwana.setPosition(RES_WIDTH - Utils.getRatio(160), RES_HEIGHT - spr_Mc_Rahwana.getHeight());
		spr_Gameplay_bg.attachChild(spr_Mc_Rahwana);
		spr_Mc_Rahwana.setVisible(true);
	}
	
	private void attachCelebrasiRahwana()
	{
			spr_Celebrasi_Rahwana = new AnimatedSprite(0, 0, Utils.getRatioW(SPR_CELEBRASI_RAHWANA_WIDTH),
					Utils.getRatioH(SPR_CELEBRASI_RAHWANA_HEIGHT), reg_Celebrasi_Rahwana, getVertexBufferManager());
		spr_Gameplay_bg.attachChild(spr_Celebrasi_Rahwana);
		spr_Celebrasi_Rahwana.setVisible(false);
	}
	
	private void attachCelebrasiRama()
	{
			spr_Celebrasi_Rama = new AnimatedSprite(0, 0, Utils.getRatioW(SPR_CELEBRASI_RAMA_WIDTH),
					Utils.getRatioH(SPR_CELEBRASI_RAMA_HEIGHT), reg_Celebrasi_Rama, getVertexBufferManager());
		
		spr_Gameplay_bg.attachChild(spr_Celebrasi_Rama);
		spr_Celebrasi_Rama.setVisible(false);
	}

	// state win

}
